/**
 *
 */
package andersonb.routebuilders;

import org.apache.camel.builder.RouteBuilder;

/**
 * @author andersonb
 *
 */
public class RotaAnderson extends RouteBuilder {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void configure() throws Exception {

		// Message Channel - polling de arquivos
		from("file:inbox-transportes").process(new FirstProcessor())
		// Messsage Translator
				.transform(body().convertToString())
				// Wire Tap
				.multicast().to("bean:tap", "direct:inicio");

		// Message Splitter
		from("direct:inicio")
			.split().xpath("/transportes/transporte")
				.to("direct:filtro");

		// Message Filter
		from("direct:filtro").filter()
			.xpath("/transporte/preco/text() <= 2000")
				.to("direct:roteador");

		// Content-based Message Router
		from("direct:roteador")
			.choice()
				.when()
				.xpath("transporte/tipo/text() = CAMELO and /transporte/preco/text() <= 1000")
					.to("direct:aceitos")
				.otherwise()
					.to("direct:rejeitados");

		// Pipeline + Message Translator
		from("direct:aceitos")
			.pipeline("bean:tradutor", "bean:propostaAceita");
		// Pipeline + Message Translator
		from("direct:rejeitados")
			.pipeline("bean:tradutor", "bean:propostaFutura");


	}
}
